# !usr/bin/python
# -*-coding: utf-8-*-
# Filename: QuickSort.py


arr = [ 2, 6, 4, 0, 1, 9, 3, 5, 8, 7 ]

def sort( arr, l, h ):
	i = l
	j = h
	k = i
	while( i < j ):
		while( j > k ):
			if( arr[k] > arr[j] ):
				tmp = arr[k]
				arr[k] = arr[j]
				arr[j] = tmp
				k = j
				break
			else:
				j = j-1

		while( i < k ):
			if( arr[k] < arr[i] ):
				tmp = arr[k]
				arr[k] = arr[i]
				arr[i] = tmp
				k = i
				break
			else:
				i = i+1

	return k


def QuickSort( arr, l, h ):
	if( l < h ):
		k = sort( arr, l, h )
		QuickSort( arr, l, k-1 )
		QuickSort( arr, k+1, h )

l = 0
h = len( arr ) - 1
QuickSort( arr, l, h )

print( arr )